package edu.gatech.oad.schedule;
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;

import java.util.Properties;

public class Email {
	private String toEmail, fromEmail, subject, body;
	private final String host = "smtp.gmail.com";
	private final String username = "jslater0808";
	private final String password = "Xenocide1991";
	private final int port = 587;
	private Properties props = new Properties();
	private Session session; 
	public Email(String emailAddress, String subjectHeader, String body) throws MessagingException{
		this.toEmail = emailAddress;
		this.fromEmail = "jslater0808@gmail.com";
		this.subject = subjectHeader;
		this.body = body;
		this.props.setProperty("mail.smtp.host", host);
		this.props.put("mail.smtp.host", "smtp.gmail.com");
		this.props.put("mail.smtp.socketFactory.port", "465");
		this.props.put("mail.smtp.socketFactory.class",
				"javax.net.ssl.SSLSocketFactory");
		this.props.put("mail.smtp.auth", "true");
		this.props.put("mail.smtp.port", "465");
		this.session = Session.getDefaultInstance(props,
				new javax.mail.Authenticator() {
					protected PasswordAuthentication getPasswordAuthentication() {
						return new PasswordAuthentication(username, password);
					}
				});
	 
	}
	
	public void sendEmail(){
		 try{
	         MimeMessage message = new MimeMessage(session);
	         message.setFrom(new InternetAddress(fromEmail));
	         message.addRecipient(Message.RecipientType.TO,
	                                  new InternetAddress(toEmail));
	         message.setSubject(subject);
	         message.setText(body);
	         Transport transport = session.getTransport("smtp");
	         transport.connect(host, port, username, password);
	         Transport.send(message);
	      }catch (MessagingException e) {
	         e.printStackTrace();
	      }
	}
	
}
